package kr.or.kosta.otr.persistence.user;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import kr.or.kosta.otr.vo.UserVO;

import com.ibatis.sqlmap.client.SqlMapClient;
@Repository("UserDao")
public class UserDaoImpl implements UserDao{
	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;
	
	
	
	@Override
	public void addUser(UserVO vo) throws SQLException {
		sqlMapClient.insert("User.addUser", vo);
	}

	@Override
	public void updateUser(UserVO vo) throws SQLException {
		sqlMapClient.update("User.updateUser", vo);
	}

	@Override
	public void deleteUser(String userId) throws SQLException {
		sqlMapClient.delete("User.deleteUser", userId);
	}

	@Override
	public UserVO getOneUser(HashMap<String, String> map) throws SQLException {
		return (UserVO) sqlMapClient.queryForObject("User.getOneUser", map);
	}

	@Override
	public ArrayList<UserVO> getAllUser(String adminId) throws SQLException {
		return (ArrayList<UserVO>) sqlMapClient.queryForList("User.getAllUser",adminId);
	}

	@Override
	public UserVO getOneUserIdByEmail(String userEmail) throws SQLException {
		return (UserVO) sqlMapClient.queryForObject("User.getOneUserIdByEmail", userEmail);
	}

	@Override
	public UserVO getOneSecretByUserId(String userId) throws SQLException {
		return (UserVO) sqlMapClient.queryForObject("User.getOneSecretByUserId", userId);
	}

	@Override
	public boolean isExist(String userId) throws SQLException {
		int i = (int) sqlMapClient.queryForObject("User.isExist", userId);
		if(i == 0)
			return true;
		else
			return false;
	}

	@Override
	public void updatePointPlus(HashMap<String, Object> map) throws SQLException {
		sqlMapClient.update("User.updatePointPlus", map);
	}

	@Override
	public void updatePointMinus(HashMap<String, Object> map) throws SQLException {
		sqlMapClient.update("User.updatePointMinus", map);
	}

	@Override
	public int getUserPoint(String userId) throws SQLException {
		return (int) sqlMapClient.queryForObject("User.getUserPoint", userId);
	}

	@Override
	public ArrayList<UserVO> getOneUserByUserId(HashMap<String, String> map) throws SQLException {
		
		return (ArrayList<UserVO>) sqlMapClient.queryForList("User.getOneUserByUserId",map);
	}

}
